<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <form action="">
        <label for="password">密码：</label><input id="password" type="password" name="password" >
    </form>
    <span class="remind"></span>
    <script>
        var password = document.querySelector("#password");
        var remind = document.querySelector(".remind");
        password.onblur = function (){
            var reg = /[\w\W]{8,}/ ; 
            var str = this.value ;
            if ( reg.test(str) ){
                switch(true){
                    case (/[a-z]/g).test(str)&&(/\d/g).test(str)&&(/[A-Z]/g).test(str)&&(/_/g).test(str) :
                        remind.innerHTML =  "密码强度高" ;
                        remind.style.color = "blue" ;
                    break ; 
                    case (/[a-zA-Z]/g).test(str)&&(/\d/g).test(str) :
                        remind.innerHTML =  "密码强度中" ;
                        remind.style.color = "yellow" ;
                    break ; 
                    case (/^\d+$|^[a-zA-Z]+$/g).test(str) :
                        remind.innerHTML =  "密码强度低" ;
                        remind.style.color = "red" ;
                    break ; 
                    default:remind.innerHTML =  "11111" ;
                    break;
                }
                flag = true ;
            } else {
                remind.innerHTML =  "密码不符合规范" ; 
                remind.style.color = "red" ;
                flag = false ;
            }
        }
    </script>
</body>
</html>